<template>
  <div class="app-container">
    <el-button type="primary" plain  size="small" @click="inspectAll" >一键质检</el-button>
    <el-table v-loading="loading" :data="detailList" >
      <el-table-column label="编号" width="100" type="index" align="center" fixed="left"
                       :index="index=>index+1"/>
      <el-table-column label="菜品名称" prop="goodsName" align="center" min-width="180"/>
      <el-table-column label="摆盘是否干净" prop="platesStatus" align="center" width="120">
        <template #default="scope">
          <span v-show="!scope.row.editFlag" :style="{'color': colors(scope.row.platesStatus)}">{{scope.row.platesStatus}}</span>
          <el-select v-show="scope.row.editFlag" v-model="scope.row.platesStatus" placeholder="是/否" clearable :style="{width: '100%'}">
            <el-option label="是" value="是"></el-option>
            <el-option label="否" value="否"></el-option>
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="菜品是否新鲜" prop="goodsStatus" align="center" width="120">
        <template #default="scope">
          <span v-show="!scope.row.editFlag" :style="{'color': colors(scope.row.goodsStatus)}">{{scope.row.goodsStatus}}</span>
          <el-select v-show="scope.row.editFlag" v-model="scope.row.goodsStatus" placeholder="是/否" clearable :style="{width: '100%'}">
            <el-option label="是" value="是"></el-option>
            <el-option label="否" value="否"></el-option>
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="制作人" prop="makeBy" align="center" width="180">
        <template #default="scope">
          <span v-show="!scope.row.editFlag">{{scope.row.makeBy}}</span>
          <el-select v-show="scope.row.editFlag" v-model="scope.row.makeBy" filterable clearable placeholder="请选择制作人"  >
            <el-option v-for="item in  dict.type.food_inspector" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="创建人" prop="createBy"  width="120" align="center"/>
      <el-table-column label="修改人" prop="updateBy" width="120" align="center"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改时间"  align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="操作" align="center" fixed="right" width="160">-->
<!--        <template #default="scope">-->
<!--          <div style="">-->
<!--            <el-button size="small"-->
<!--                       type="text"-->
<!--                       icon="CircleCheck"-->
<!--                       v-show="scope.row.editFlag"-->
<!--                       @click="submit(scope.row, $index)">保存-->
<!--            </el-button>-->
<!--            <el-button size="small"-->
<!--                       type="text"-->
<!--                       icon="CircleClose"-->
<!--                       v-show="scope.row.editFlag"-->
<!--                       @click="cancel(scope.row, $index)">取消-->
<!--            </el-button>-->
<!--            <el-button size="small"-->
<!--                       icon="Edit"-->
<!--                       type="text"-->
<!--                       v-show="!scope.row.editFlag"-->
<!--                       @click="edit(scope.row, $index)">编辑-->
<!--            </el-button>-->
<!--          </div>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>
  </div>
</template>

<script>
import {buffetBatchEdit, list, update} from "@/api/examine/buffet/detail";
  export default {
    name: "BuffetExamineDetail",
    dicts: ['food_inspector'],
    data() {
      return {
        // 遮罩层
        loading: true,
        detailList: [],
      };
    },
    created() {
      this.id = this.$route.params && this.$route.params.id;
      this.getList();
    },
    methods: {
      colors(status) {
        if (status === "是") {
          return '#2a9c4a';
        } else if (status === '否') {
          return '#FF0000';
        } else {
          return '#fe9f29';
        }
      },
      /** 查询列表 */
      getList() {
        this.loading = true;
        list({
          examineId: this.id,
        }).then(response => {
          response.rows.map(item=>{
            item.editFlag=true
          })
          this.detailList = response.rows;
          this.loading = false;
        });
      },
      submit: function(row, index) {
        let updateData = {
          id: row.id,
          platesStatus: row.platesStatus,
          goodsStatus: row.goodsStatus,
          makeBy: row.makeBy,
        }
        update(updateData).then(res => {
          this.$modal.msgSuccess("更新成功");
          row.editFlag = false;
          this.getList();
        })
      },
      cancel: function(row, index) {
        row.editFlag = false;
        this.getList();
      },
      edit: function(row, index) {
        row.editFlag = true;
        this.$set(this.detailList, index, row);
      },
      inspectAll(){
        let postData=[]
        this.detailList.map(item=>{
          let postItem={
            id:item.id,
            platesStatus:'是',
            goodsStatus:'是',
            makeBy:item.makeBy
          }
          postData.push(postItem)
        })
        buffetBatchEdit(postData).then(res=>{
          this.$message.success('提交成功')
          this.getList()
        })
      }
    }
  };
</script>
